import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


/**
 * 
 * this class is the main screen gui
 *
 */
public class MainScreen extends JFrame{
	

	
	private final JButton btnEntrenceForStudents = new JButton("Entrence for students");
	private final JButton btnEntrenceForTeachers = new JButton("Entrence for teachers");
	private final JButton btnEntrenceForParents = new JButton("Entrence for parents");
	private final JLabel lblWellcomeTo = new JLabel("Wellcome to Academic Managment Tool");
	/**
	 * exit button
	 */
	private final JButton btnExit = new JButton("EXIT");
	public static JPanel MainPanel = new JPanel();
	/**
	 * MangmentUI gui
	 */
	private MangmentUI mng;
	/**
	 * loginUI gui
	 */
	private loginUI login;
	/**
	 *  help button
	 */
	public JButton btnHelp = null;
	
	public MainScreen() {
		super();
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.out.println("DONT CLOSE ME!!!!!!!!");
				Global.logOut();
				System.exit(0);
			}
		});
		initialize();
	}

	private void initialize() {
		mng = new MangmentUI();
		login = new loginUI();
		new Global(this,MainPanel);
		this.setLocation(360, 150);
		this.setSize(500, 400);
		getContentPane().add(MainPanel);
		MainPanel.setLayout(null);
		lblWellcomeTo.setBounds(108, 23, 255, 48);
		MainPanel.add(lblWellcomeTo);
		
		btnEntrenceForParents.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				login.SetUserType(2) ;
				MainPanel.setVisible(false);
				login.setVisible(true);
				setContentPane(login);
			}
		});
		
		btnEntrenceForStudents.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				login.SetUserType(1) ;
				MainPanel.setVisible(false);
				login.setVisible(true);
				setContentPane(login);
			}
		});
		
		btnEntrenceForTeachers.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				login.SetUserType(3);
				MainPanel.setVisible(false);
				login.setVisible(true);
				setContentPane(login);
			}
		});
		
		btnEntrenceForStudents.setBounds(136, 87, 181, 48);
		MainPanel.add(btnEntrenceForStudents);
		btnEntrenceForTeachers.setBounds(134, 146, 181, 48);
		MainPanel.add(btnEntrenceForTeachers);
		btnEntrenceForParents.setBounds(134, 205, 181, 48);
		MainPanel.add(btnEntrenceForParents);
		
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Global.logOut();
				System.exit(0);
			}
		});
		btnExit.setBounds(184, 295, 86, 25);
		MainPanel.add(btnExit);
		
		JLabel lblMangment = new JLabel("Management");
		lblMangment.setForeground(Color.BLUE);
		lblMangment.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
		lblMangment.addMouseListener(new MouseAdapter() {
			
				
			
			public void mouseClicked(MouseEvent arg0) {
				MainPanel.setVisible(false);
				mng.setVisible(true);
				setContentPane(mng);
			}
		});
		lblMangment.setBounds(26, 332, 86, 19);
		MainPanel.add(lblMangment);
		


		this.login.btnBack.addActionListener(new ActionListener() {  // back from login UI
			public void actionPerformed(ActionEvent arg0) {
				setContentPane(MainPanel);
				MainPanel.setVisible(true);
			}
		});

		
		this.mng.btnBack.addActionListener(new ActionListener() { //back from management UI
			public void actionPerformed(ActionEvent arg0) {
				setContentPane(MainPanel);
				MainPanel.setVisible(true);
			}
		});
		
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Choose your option according to your Role");
				  System.out.println("user press Help button");
			}
		});
		MainPanel.add(btnHelp,null);
		
		this.addWindowFocusListener(new WindowAdapter() {
		    public void windowGainedFocus(WindowEvent e) {
		    	btnEntrenceForStudents.requestFocusInWindow();
		    }
		});
		this.setTitle("Academic Managment Tool");
		this.setVisible(true);

	}
	
}
